<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>后台管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="../css/font.css">
		<link rel="stylesheet" href="../css/xadmin.css">
		<script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
		<script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../js/xadmin.js"></script>
	</head>

	<body class="layui-body" style="left:0px;">
		<div class="x-body">
			<table class="layui-hide" id="demo" lay-filter="test"></table>
		</div>
	
		<script type="text/html" id="toolbarDemo">
		  <div class="layui-btn-container">
		    <button class="layui-btn layui-btn-sm" lay-event="getCheckData" onclick="x_admin_show('申请维修','./applyFix.html')">申请维修</button>
		    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="getCheckData" onclick="revoke()">撤销申请</button>
          </div>
		</script>
		
		
		<script type="text/javascript">
			layui.use(['table', 'layer'], function() {
					var layer = layui.layer;
					var table = layui.table;
					table.render({
					    elem: '#demo'
					    ,id: 'fixTable'
					    ,height: 605
					    ,width:1335
					    ,url: 'findFixTable' //数据接口
					    ,page: true //开启分页
					    ,toolbar: '#toolbarDemo' //开启工具栏
					    ,request: {
					   		pageName: 'pageNo' //页码的参数名称，默认：page
					    	,limitName: 'pageSize' //每页数据量的参数名，默认：limit
					  	}
					    ,cols: [[ //表头
					      {type: 'radio', fixed: 'left'}
					      ,{field: 'fixBillId', title: 'ID', width:80, sort: true, fixed: 'left'}
					      ,{field: 'breakObject', title: '需要维修的物件', width:200}
					      ,{field: 'breakCause', title: '问题描述', width: 400}
					      ,{field: 'fixBillSendTime', title: '申请时间', width:120, sort: true
					    	   ,templet:function(d){
					    		   return toMyDateString(d.fixBillSendTime)
					    	   }	    
					      }
					      ,{field: 'workerName', title: '维修师傅', width: 100}
					      ,{field: 'workerTelephone', title: '联系方式', width:150} 
					      ,{field: 'applyTime', title: '预约时间', width:120
					    	  ,templet:function(d){
                                  if(d.applyTime!=null&&d.applyTime.toString().trim()!=""){
                                       return toMyDateString(d.applyTime);
                                  }
                                  return "";
					    	  }
                           }
					      ,{fixed: 'right', title: '状态', width: 105
                              ,templet:function(d){
                                  if(d.enable==2){
                                      return "已撤销";
                                  }
                                  if(d.isCheck){
                                       var status="处理中";
                                          if(d.isApply){
                                              status="已安排师傅";
                                              if(d.isFinish){
                                                  status="已完成";
                                              }
                                          }
                                          return status;
                                  }else{
                                      return "待处理";
                                  }
                              }
                          }
					      
					    ]]
					 
					  }
					);
			});

			function toMyDateString(timeMillis){
				var time = new Date(timeMillis);
				var month = time.getMonth()+1;
				if(month<10) month='0'+month;
				var day = time.getDate();
				if(day<10) day='0'+day;
	            return time.getFullYear()+"-"+month+"-"+day;;
			}
			
			
			//撤销申请
			function revoke(){
				var checkStatus = table.checkStatus('fixTable'); //idTest 即为基础参数 id 对应的值
				console.log(checkStatus.data) //获取选中行的数据
				console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
				console.log(checkStatus.isAll ) //表格是否全选
				
				if(checkStatus.data.length==1){
					if(checkStatus.data[0].enable==1&&checkStatus.data[0].isApply==0){
						var data = {};
						data.fixBillId = checkStatus.data[0].fixBillId;
						data.enable = 2;
						$.ajax({
							type:"post",
			                url:"updateFix",
			                async:true,
			                data :data,
			                success:function(result){
			                	if(result.msg=='success'){
			                		layer.alert("撤销成功", {icon: 1},function () {
			                			location.reload();
			                		});
			                	}else{
			                		layer.alert("撤销失败", {icon: 2});
			                	}
			                },
			                error:function(){
			                	layer.alert("撤销失败", {icon: 2});
			                }
						});
					}else{
						layer.alert("不可撤销", {icon: 2});
					}
					
				}else{
					layer.alert("请选择一行", {icon: 0});
				}
			};
		</script>
	</body>

</html>